package org.mineground.commands.irc.query;

import org.jibble.pircbot.Colors;
import org.jibble.pircbot.User;
import org.mineground.Main;
import org.mineground.handlers.irc.PrivateCommandExecutor;
import org.mineground.handlers.irc.UserLevel;
import org.mineground.player.PasswordHandler;

/**
 * @name ChangePassword.java
 * @author Daniel Koenen (2012)
 */
public class ChangePassword implements PrivateCommandExecutor {
    @Override
    public void onPrivateCommand(String sender, String command, String[] args) {
        if (args.length < 3) {
            Main.getInstance().getIRCHandler().sendNotice(sender, Colors.RED + "Usage: " + Colors.NORMAL + "/msg Minecraft !changepassword [player name] [old password] [new password]");
            return;
        }
        
        if (!PasswordHandler.changePassword(args[0], args[1], args[2])) {
            Main.getInstance().getIRCHandler().sendNotice(sender, Colors.RED + "Error: Incorrect player name / password.");
            return;
        }
        
        Main.getInstance().getIRCHandler().sendNotice(sender, Colors.DARK_GREEN + "Your password has been changed, please remember it for later use."); 
    }

    @Override
    public void onCommand(User sender, UserLevel level, String channel, String command, String[] args) {
        Main.getInstance().getIRCHandler().sendMessage(channel, Colors.RED + "Usage: " + Colors.NORMAL + "/msg Minecraft !changepassword [player name] [old password] [new password]");
    }
}
